{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
module Language.Dependencies.Adaptors.C where

-- container
import Data.Tree (Tree(Node,rootLabel))
import Data.Maybe
-- local imports
import Language.Dependencies.Language as L
import Language.Dependencies.Term2tree (data2tree)

import Data.ByteString.Char8(pack)

import Language.C.Syntax.AST
import Language.C.Syntax.Constants
import Language.C.Data.Position
import Language.C.Data.Node
import Language.C.Parser
import Language.C.Pretty

import Text.PrettyPrint.HughesPJ

import Generics.MultiRec.Languages.C.C

languagec = Language 
  { L.name=        "C" 
  , syntax=        "C" 
  , exts=          [".c"] 
  , parse=         parC
  , toTree=        (data2tree TheCTranslUnit :: CTranslUnit -> Tree String)
  , srcLoc=        undefined
  , adjustSrcLoc=  Nothing
  , srcLoctype=    (Coordinate undefined undefined)
  , typerep = Just TheCTranslUnit
}


parC :: String -> Either Error CTranslUnit
parC s =
  case parseC (pack s) (Position "init" 0 0) of
    Right c   -> Right c
    Left e -> Left $ ErrMessage (show e)


instance Show CDesignator where
  show c = "CDesignator"

instance Show CInit where
  show n = "CInit"

instance Show CTypeQual where
  show n = "CTypeQual"

instance Show CAsmOperand where
  show n = "CAsmOperand"

instance Show CStrLit where
  show n = "CStrLit"

instance Show CExpr where
  show n = "CExpr"

instance Show CDeclSpec where
  show n = "CDeclSpec"

instance Show CDeclr where
  show n = "CDeclr"

instance Show CDerivedDeclr where
  show n = "CDerivedDeclr"

instance Show CAttr where
  show n = "CAttr"

instance Show CDecl where
  show n = "CDecl"

instance Show CBlockItem where
  show n = "CBlockItem"

instance Show CStat where
  show n = "CStat"

instance Show CExtDecl where
  show n = "CExtDecl"

instance Show Language.C.Syntax.Constants.CIntRepr where
  show n = "CIntRepr"

instance Show
         (Language.C.Syntax.Constants.Flags
            Language.C.Syntax.Constants.CIntFlag) where
  show n = "CIntFlag"
